﻿

using FeedbackNetwork.network;

namespace FeedbackNetwork.dataset
{
    class MnistData
    {
        private readonly uint label;
        private readonly float[] image;
        private readonly uint width = 28;
        private readonly uint height = 28;

        public MnistData()
        {
            this.label = 0;
            this.image = null;
        }

        public MnistData(uint label)
        {
            this.label = label;
            this.image = null;
        }

        public MnistData(float[] image)
        {
            this.label = 0;
            this.image = image;
        }

        public MnistData(uint label, float[] image)
        {
            this.label = label;
            this.image = image;
        }

        public uint GetLabel()
        {
            return this.label;
        }

        public float[] GetLabelOneHot()
        {
            float[] result = new float[10];
            for (int i = 0; i < result.Length; i++)
                result[i] = 0f;
            result[this.label] = 1f;
            return result;
        }

        public float[] GetImage()
        {
            return this.image;
        }

        public uint GetWidth()
        {
            return this.width;
        }

        public uint GetHeight()
        {
            return this.height; 
        }

        public FloatTensor GetImageTensor()
        {
            FloatTensor result = new FloatTensor();
            result.SetData(this.image, new int[] { 1, (int)this.width * (int)this.height });
            return result;
        }

        public FloatTensor GetLabelTensor()
        {
            FloatTensor result = new FloatTensor();
            result.SetData(this.GetLabelOneHot(), new int[] { 1, 10 });
            return result;
        }

    }
}
